/*
 * @Author: wangdazhuang
 * @Date: 2024-10-16 19:14:58
 * @LastEditTime: 2025-01-21 09:19:54
 * @LastEditors: wangdazhuang
 * @Description: 
 * @FilePath: /pornhub_app/lib/views/mine/download/download_page.dart
 */
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

import '../../../components/no_more/no_data_sliver_list.dart';
import '../../../components/short_widget/video_download_cell.dart';
import '../../../utils/color.dart';
import '../../../utils/m3u8_download/m3u8_downloader_manager.dart';
import '../../../utils/extension.dart';

class DownloadPage extends StatelessWidget {
  const DownloadPage({super.key});

  AppBar _buildAppBar() => AppBar(
        title: const Text('离线下载'),
        titleTextStyle: TextStyle(
          fontSize: 17,
          color: COLOR.hexColor('#fff'),
          fontWeight: FontWeight.w600,
        ),
      );

  Widget _buildBody() {
    final records = M3u8DownloadManager.allRecordsByCreatedAtDesc.toList();
    return CustomScrollView(
      slivers: [
        NoDataSliverList.separated(
          itemCount: records.length,
          itemBuilder: (_, index) => VideoDownloadCell(record: records[index]),
          separatorBuilder: (_, __) => SizedBox(height: 10.w),
        )
      ],
    ).baseMarginLtr;
  }

  @override
  Widget build(BuildContext context) =>
      Scaffold(appBar: _buildAppBar(), body: _buildBody());
}
